package com.qf.studentmanager.service;

import com.qf.studentmanager.dao.CourseDao;
import com.qf.studentmanager.dao.UserDao;
import com.qf.studentmanager.model.Course;

import java.sql.SQLException;
import java.util.List;

public class CourseService {
    CourseDao courseDao = new CourseDao();

    public Integer addCourse(Course course) {
        Course course1 = courseDao.getCourseByName(course.getCourseName());
        if (course1 != null) {//重复了
            return -2;
        }

        Integer integer = courseDao.addCourse(course);
        return integer;
    }

    public Integer deleteCourse(int id){
        try {
            Integer integer = courseDao.deleteCourse(id);
            return integer;
        } catch (SQLException e) {
            e.printStackTrace();
            return -1;
        }
    }

    public List<Course> getCoursesByGid(String gid) {
        return courseDao.getCoursesByGid(gid);
    }
}